import { Table } from 'antd';
import React, { useState } from 'react';
const columns = [
    {
        title: '任务名称',
        dataIndex: 'name',
    },
    {
        title: '负责人',
        dataIndex: 'person',
    },
    {
        title: '任务状态',
        dataIndex: 'status',
    },
    {
        title: '任务分类',
        dataIndex: 'classify',
    },
    {
        title: '优先级',
        dataIndex: 'priority',
        sorter: {
            compare: (a, b) => a.priority - b.priority,
            multiple: 3,
        },
    },
    {
        title: '任务完成度',
        dataIndex: 'completion',
        sorter: {
            compare: (a, b) => a.completion - b.completion,
            multiple: 3,
        },
    },
    {
        title: '截至日期',
        dataIndex: 'deadTime',
        sorter: {
            compare: (a, b) => a.deadTime - b.deadTime,
            multiple: 3,
        },
    },
    {
        title: '完成/暂停日期',
        dataIndex: 'completionTime',
        sorter: {
            compare: (a, b) => a.completionTime - b.completionTime,
            multiple: 3,
        },
    },
    {
        title: '创建时间',
        dataIndex: 'createdTime',
        sorter: {
            compare: (a, b) => a.createdTime - b.createdTime,
            multiple: 3,
        },
    },
];
const data = [];

for (let i = 0; i < 6; i++) {
    data.push({
        key: i,
        name: `日常维护`,
        person: `fox`,
        status: `--`,
        classify:`--`,
        priority: `${i+1}`,
        completion:`--`,
        deadTime: `--`,
        completionTime:`--`,
        createdTime:`--`
    });
}

const App = () => {
    const [selectedRowKeys, setSelectedRowKeys] = useState([]);

    const onSelectChange = (newSelectedRowKeys) => {
        console.log('selectedRowKeys changed: ', selectedRowKeys);
        setSelectedRowKeys(newSelectedRowKeys);
    };

    const rowSelection = {
        selectedRowKeys,
        onChange: onSelectChange,
        selections: [
            Table.SELECTION_ALL,
            Table.SELECTION_INVERT,
            Table.SELECTION_NONE,
            {
                key: 'odd',
                text: 'Select Odd Row',
                onSelect: (changableRowKeys) => {
                    let newSelectedRowKeys = [];
                    newSelectedRowKeys = changableRowKeys.filter((_, index) => {
                        if (index % 2 !== 0) {
                            return false;
                        }

                        return true;
                    });
                    setSelectedRowKeys(newSelectedRowKeys);
                },
            },
            {
                key: 'even',
                text: 'Select Even Row',
                onSelect: (changableRowKeys) => {
                    let newSelectedRowKeys = [];
                    newSelectedRowKeys = changableRowKeys.filter((_, index) => {
                        if (index % 2 !== 0) {
                            return true;
                        }

                        return false;
                    });
                    setSelectedRowKeys(newSelectedRowKeys);
                },
            },
        ],
    };
    const onChange = (pagination, filters, sorter, extra) => {
        console.log('params', pagination, filters, sorter, extra);
    };
    return <Table rowSelection={rowSelection} columns={columns} dataSource={data} onChange={onChange} />;
};

export default App;